//
//  ViewController.m
//  13. PickerView
//
//  Created by iD Student on 7/8/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    colorList = [[NSMutableArray alloc]init];
    [colorList addObject:[NSString stringWithFormat:@"Red"]];
    [colorList addObject:[NSString stringWithFormat:@"Green"]];
    [colorList addObject:[NSString stringWithFormat:@"Blue"]];
    [colorList addObject:[NSString stringWithFormat:@"Gray"]];
    [colorList addObject:[NSString stringWithFormat:@"Cyan"]];
    [colorList addObject:[NSString stringWithFormat:@"Orange"]];
    
    colorColors = [[NSMutableArray alloc]initWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], [UIColor grayColor], [UIColor cyanColor], [UIColor orangeColor], nil];
    
    myDictionary = [NSDictionary dictionaryWithObjects:colorColors forKeys:colorList];
    
    colorPicker.delegate = self;
    colorPicker.dataSource = self;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return colorList.count;
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return  [colorList objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    selectedRow = row;
}

- (IBAction)changePressed:(id)sender
{
    UIColor *selectedColor = [colorColors objectAtIndex:selectedRow];
    self.view.backgroundColor = selectedColor;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
